<?php

use think\migration\Migrator;
use think\migration\db\Column;

class LyActivity extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('activity')
            ->addColumn('name', 'string', ['limit' => 255, 'comment' => '活动名称',"after"=>"id"])
            ->addColumn('cover_img', 'string', ['limit' => 255, 'null' => true, 'comment' => '活动图片',"after"=>"name"])
            ->addColumn('type', 'string', ['limit' => 100, 'comment' => '活动类型',"after"=>"cover_img"])
            ->addColumn('scene', 'json', ['null' => true,'comment'=>'活动触发场景','after' => 'type'])
            ->addColumn('recharge_price', 'decimal', ['precision'=>10,'scale'=>'2', 'default' => '0.00','comment'=>'充值金额','after' => 'scene'])
            ->addColumn('send_currency', 'integer', ['limit' => 11, 'default' => '0', 'comment' => '赠送币数',"after"=>"recharge_price"])
            ->addColumn('sum_currency', 'integer', ['limit' => 11, 'default' => '0', 'comment' => '总共充值币数',"after"=>"send_currency"])
            ->addColumn('url', 'string', ['limit' => 255, 'null' => true, 'default' => '', 'comment' => '跳转链接',"after"=>"sum_currency"])
            ->addColumn('status', 'string', ['limit' => 100, 'comment' => '状态',"after"=>"url"])
            ->addColumn('start_at', 'timestamp', ['default' => null,'null' => true, 'comment' => '开始时间',"after" => "status"])
            ->addColumn('end_at', 'timestamp', ['default' => null,'null' => true, 'comment' => '结束时间',"after" => "start_at"])
            ->addColumn('applet_ids', 'json', ['null' => true,'comment'=>'applet表ids','after' => 'end_at'])
            ->addColumn('operator_id', 'integer', ['limit' => 11,'default' => 0, 'comment' => '操作人员ID',"after" => "applet_ids"])
            ->addColumn('created_at', 'timestamp', ['default' => null,'comment' => '创建时间',"after" => "operator_id"])
            ->addColumn('updated_at', 'timestamp', ['default' => null,'comment' => '修改时间',"after" => "created_at"])
            ->addColumn('deleted_at', 'timestamp', ['null' => true, 'default' => null,'comment' => '删除时间',"after" => "updated_at"])
            ->setComment('活动表')
            ->create();

        $this->table('activity_statistics')
            ->addColumn('activity_id', 'integer', ['limit' => 11,'null' => true, 'default' => '0', 'comment' => '活动id',"after"=>"id"])
            ->addColumn('date', 'string', ['limit' => 10, 'null' => true, 'default' => '', 'comment' => '日期',"after"=>"activity_id"])
            ->addColumn('click_count', 'integer', ['limit' => 11, 'null' => true, 'default' => '0', 'comment' => '点击次数',"after"=>"date"])
            ->addColumn('click_uv', 'integer', ['limit' => 11, 'null' => true, 'default' => '0', 'comment' => '点击人数',"after"=>"click_count"])
            ->addColumn('recharge_uv', 'integer', ['limit' => 11, 'null' => true, 'default' => '0', 'comment' => '充值人数',"after"=>"click_uv"])
            ->addColumn('recharge_amount', 'decimal', ['precision'=>10,'null' => true, 'scale'=>'2','default' => '0.00','comment'=>'充值金额','after' => 'recharge_count'])
            ->addColumn('created_at', 'timestamp', ['default' => null, 'null' => true, 'comment' => '创建时间',"after" => "operator_id"])
            ->addColumn('updated_at', 'timestamp', ['default' => null, 'null' => true, 'comment' => '修改时间',"after" => "created_at"])
            ->addColumn('deleted_at', 'timestamp', ['null' => true, 'default' => null,'comment' => '删除时间',"after" => "updated_at"])
            ->setComment('活动数据统计表')
            ->create();

    }

    public function down()
    {
        $this->table('activity')
            ->drop();
        $this->table('activity_statistics')
            ->drop();
    }
}
